<?php 
//I.F. Nuevo: 2010-03-28; ramarin
require_once('../../../config.php');
require_once($CFG->libdir.'/gdlib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');

function get_my_courses_moosisca($select = "mw.id, c.fullname", $where, $sort='c.fullname', $dir='ASC', $page=0, $recordsperpage=0) {

  global $CFG;

  $LIKE      = sql_ilike();
  $fullname  = sql_fullname();

  if ($sort) {
      $sort = ' ORDER BY '. $sort .' '. $dir;
  } 

  return get_recordset_sql("SELECT $select
                            FROM {$CFG->prefix}course c
                              INNER JOIN {$CFG->prefix}moosisca_workflow mw ON c.id = mw.courseid
                           WHERE $where $sort", $page, $recordsperpage);
}

function get_pending_approvation_courses($select = "mw.id, c.fullname", $where, $sort='c.fullname', $dir='ASC', $page=0, $recordsperpage=0) {

  global $CFG;

  $LIKE      = sql_ilike();
  $fullname  = sql_fullname();

  if ($sort) {
      $sort = ' ORDER BY '. $sort .' '. $dir;
  }

  return get_recordset_sql("SELECT $select
                            FROM {$CFG->prefix}course c
                              INNER JOIN {$CFG->prefix}moosisca_workflow mw ON c.id = mw.courseid
                           WHERE $where $sort", $page, $recordsperpage);
}

function get_observations_course($select = "mwh.id, c.fullname", $where, $sort='mwh.timecreated', $dir='DESC', $page=0, $recordsperpage=0) {

  global $CFG;

  if ($sort) {
      $sort = ' ORDER BY '. $sort .' '. $dir;
  }

  return get_recordset_sql("SELECT $select
                            FROM {$CFG->prefix}moosisca_workflow mw
                              INNER JOIN {$CFG->prefix}moosisca_workflow_history mwh ON mw.id = mwh.workflowid
                              INNER JOIN {$CFG->prefix}user u ON u.id = mwh.userid
                           WHERE $where $sort", $page, $recordsperpage);
}